package com.sale.plugins;

import com.apache.api.vo.ParamsVo;
import com.apache.database.constant.SpringContextLoader;
import com.apache.ius.plugin.CustomMethodPlugin;
import com.apache.match.manager.DealMatchingManager;
import org.apache.log4j.Logger;

import java.util.Map;

/**
 * 下单时处发队列撮合
 */
public class SaleSaveDealOrderPluginImpl implements CustomMethodPlugin {

    private Logger log = Logger.getLogger(getClass());

    private DealMatchingManager dealMatchingManager;

    public Object beforeInvoke(Map<String, Object> param) {
        return null;
    }

    public Object doInvoke(Map<String, Object> param) {
        return null;
    }

    /**
     * 规则校验入口（专门给系统公式规则提供的）
     *
     * @param paramsVo
     */
    public void run(ParamsVo paramsVo) {
        beforeInvoke(paramsVo.getParams());
    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public Object afterInvoke(Map<String, Object> param) {
        //		GoEasy goEasy = new GoEasy("fcdd060e-c3ee-4003-bdd7-d68785a77d19");
        //		goEasy.publish("my_channel", "后台发送的消息!");
        if (null == dealMatchingManager) {
            dealMatchingManager = (DealMatchingManager) SpringContextLoader
                    .getBean("dealMatchingManager");
        }
        ParamsVo vo = new ParamsVo();
        vo.setParams(param);
        log.info("委托提交...");
        dealMatchingManager.saveInfo(vo);
        return null;
    }
}
